package com.tulingxueyuan.mall.controller;

import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.modules.ums.model.UmsMemberReceiveAddress;
import com.tulingxueyuan.mall.modules.ums.service.UmsMemberReceiveAddressService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：扫地僧
 * @date ：2022/3/12/0012 10:21:36
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description:
 **/
@Controller
@Api(tags = "MemberAddressController", description = "收货地址服务接口")
@RequestMapping("/member/address")
@ResponseBody
public class MemberAddressController {
    @Autowired
    private UmsMemberReceiveAddressService addressService;
    /**
     * method = "post"), (url = "/member/address/add");
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody UmsMemberReceiveAddress address){
        Boolean result = addressService.add(address);
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @PostMapping("/update/{id}")
    @ResponseBody
    public CommonResult update(@PathVariable long id,@RequestBody UmsMemberReceiveAddress address){
        address.setId(id);
        Boolean result = addressService.edit(address);
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Long id){
        Boolean result = addressService.delete(id);
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    /**
     * get("/member/address/list"
     */
    @GetMapping("/list")
    public CommonResult list(){
        List<UmsMemberReceiveAddress> list = addressService.listByMemberId();
        return CommonResult.success(list);
    }
}
